package com.zjh.photoshopstudy.app.user;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.zjh.photoshopstudy.Model.AppUserEntity;
import com.zjh.photoshopstudy.R;
import com.zjh.photoshopstudy.Utils.App;
import com.zjh.photoshopstudy.Utils.Data;
import com.zjh.photoshopstudy.Utils.SharePreferencesUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class CommentActivity extends AppCompatActivity {
    CommentAdapter adapter;
    TextView tip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment);
        if (!EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().register(this);
        int uid = (int) SharePreferencesUtils.getLoginUser(this).getId();
        UserHttp.getComment(uid);
        RecyclerView recyclerView = findViewById(R.id.commentList);
        tip = findViewById(R.id.no_comment_tip4);
        adapter = new CommentAdapter(null, this);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void getNewComment(GetNewComment e) {
        int uid = (int) SharePreferencesUtils.getLoginUser(App.getContext()).getId();
        SharePreferencesUtils.saveNewCommentCount(this, uid, e.getList().size());
        if (e.getList().size() > 0) {
            adapter.setvCommentEntityList(e.getList());
            adapter.notifyDataSetChanged();
            tip.setVisibility(View.INVISIBLE);
        } else {
            tip.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onDestroy() {
        if (EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().unregister(this);
        super.onDestroy();
    }
}
